package com.wuyan.locationdog.adapter

import android.graphics.Color
import android.view.View
import android.widget.TextView
import androidx.annotation.LayoutRes
import com.arcsoft.commonbase.bean.OrderListBeanContent
import com.arcsoft.commonbase.ext.gone
import com.arcsoft.commonbase.ext.visible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.wuyan.locationdog.R
import com.wuyan.locationdog.help.DeviceHelp


class OrderListAdapter(@LayoutRes layoutResId: Int, data: MutableList<OrderListBeanContent>?) :
    BaseQuickAdapter<OrderListBeanContent, BaseViewHolder>(layoutResId, data) {


    override fun convert(holder: BaseViewHolder, item: OrderListBeanContent) {
        holder.apply {
            //订单状态 1待付款 5已完成 6已关闭
            var orderStatus = "月"

            getView<TextView>(R.id.orderEditAmount).setTextColor(Color.parseColor("#8C8C8C"))
            when (item.orderStatus) {
                1 -> {
                    orderStatus = "待付款"
                    getView<TextView>(R.id.orderStatus).setTextColor(Color.parseColor("#6E4DF3"))
                    getView<View>(R.id.btnPay).visible()
                    getView<TextView>(R.id.orderEditAmount).setTextColor(Color.parseColor("#6E4DF3"))
                }
                5 -> {
                    orderStatus = "已完成"
                    getView<TextView>(R.id.orderStatus).setTextColor(Color.parseColor("#2BAD84"))
                    getView<View>(R.id.btnPay).gone()

                }
                else -> {
                    orderStatus = "已取消"
                    getView<TextView>(R.id.orderStatus).setTextColor(Color.parseColor("#8C8C8C"))
                    getView<View>(R.id.btnPay).gone()

                }
            }
            getView<TextView>(R.id.orderStatus).text = orderStatus

            getView<TextView>(R.id.deviceName).text = DeviceHelp.getDeviceName(item)
            getView<TextView>(R.id.imei).text = item.imei
            getView<TextView>(R.id.createTime).text = item.createTime
            getView<TextView>(R.id.orderEditAmount).text = "¥" + item.orderEditAmount
            val orderVirtualService = item.orderVirtualServiceList.first()
            //有效期单位 1 日 2月 3年
            var unit = "月"
            if (orderVirtualService.effectiveUnit == 1) {
                unit = "日"
            } else if (orderVirtualService.effectiveUnit == 2) {
                unit = "个月"
            } else {
                unit = "年"
            }
            getView<TextView>(R.id.packageContent).text =
                orderVirtualService.commodityName + " | " + orderVirtualService.containNum + orderVirtualService.stockUnit + " | 有效期" + orderVirtualService.effectiveTime + unit


        }
    }
}


